//
//  COBalanceHeadView.swift
//  CocoProject
//
//  Created by Vill on 2023/11/14.
//

import UIKit

class COBalanceHeadView: UIView {
 
    lazy var containView: UIView = {
        let contain = UIView()
        contain.layer.cornerRadius = PTW(10)
        contain.layer.masksToBounds = true
        contain.backgroundColor = UIColor.gradientFromColor(colors: [UIColor.colorWithHex("#7038FF").cgColor,UIColor.colorWithHex("#FF3DE1").cgColor], direction: .Horizontal, range: SCREENWIDTH - PTW(40))
        return contain
    }()
    
    lazy var starImg: UIImageView = {
        let star = UIImageView()
        star.image = KImaged("coco_mine_star")
        return star
    }()
    
    lazy var balanceLbl : UILabel = {
        let label = UILabel.init()
        label.font = UIFont.pingfangFont(ofSize: PTW(50), weight: .heavy)
        label.textColor = UIColor.white
        let model = COUserInfoManager.shared.curUser
        label.text = "\(model?.userResponse.balance ?? 0)"
        return label
    }()
    
    lazy var detailLbl : UILabel = {
        let label = UILabel.init()
        label.font = UIFont.pingfangFont(ofSize: PTW(13), weight: .medium)
        label.textColor = UIColor.white.withAlphaComponent(0.5)
        label.text = "Current Balance"
        return label
    }()

    override init(frame: CGRect) {
        super.init(frame: frame)
        setUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUI(){
        addSubview(self.containView)
        self.containView.addSubview(self.balanceLbl)
        self.containView.addSubview(self.starImg)
        self.containView.addSubview(self.detailLbl)
        self.containView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(PTW(20))
            make.right.equalToSuperview().offset(-PTW(20))
            make.top.equalToSuperview().offset(PTW(5))
            make.bottom.equalToSuperview().offset(-PTW(5))
        }
        self.balanceLbl.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(PTW(25))
        }
        self.starImg.snp.makeConstraints { make in
            make.centerY.equalTo(self.balanceLbl)
            make.trailing.equalTo(self.balanceLbl.snp.leading).offset(-PTW(5))
            make.size.equalTo(PTW(30))
        }
        self.detailLbl.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(self.balanceLbl.snp.bottom).offset(PTW(5))
        }
    }

    func updateBalance(){
        let model = COUserInfoManager.shared.curUser
        self.balanceLbl.text = "\(model?.userResponse.balance ?? 0)"
    }
    
}
